/*
 * @Author: 橘子
 * @Project_description: 路由方法
 * @Description: 代码是我抄的，不会也是真的
 */

import queryParams from './queryParams.js'
import deepJSON from './deepMerge.js'
let route = {}

/**
 * @desc: 路由方法
 * @param {*} param
 * @return {*}
 * @Author: 橘子
 */
route.push = function(param = {}) {
	let {
		path,
		query = {},
		params = {},
		time = 800,
	} = param
	//处理params
	setTimeout(() => {
		//处理params
		let data = deepJSON(query, params)
		uni.navigateTo({
			url: path + queryParams(data)
		})
	}, time)
}

/**
 * @desc:回退
 * @param {*} param
 * @return {*}
 * @Author: 橘子
 */
route.back = function(param = {}) {
	let {
		msg,
		time = 800,
		delta = 1
	} = param
	if (msg) {
		uni.showToast({
			icon: 'none',
			title: msg,
		})
	}
	setTimeout(() => {
		uni.navigateBack({
			delta,
		})
	}, time)
}

/**
 * @desc: 去那
 * @param {*} param
 * @return {*}
 * @Author: 橘子
 */
route.to = function(param = {}) {
	let {
		path,
		msg,
		params = {},
		query = {},
		time = 800
	} = param
	// 如果有消息
	if (msg) {
		uni.showToast({
			icon: 'none',
			title: msg,
		})
	}
	let data = deepJSON(query, params)
	setTimeout(() => {
		//处理params
		let data = deepJSON(query, params)
		uni.reLaunch({
			url: path + queryParams(data)
		})
	}, time)
}

export default route
